home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Halma 1.1.source Folder / Halma ƒ / Shell ƒ / about.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-25  |  5.2 KB  |  206 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles displaying the about box.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "graphics.h"        /* needs to come first because it defines WindowDataHandle */
  25. #include "about.h"
  26. #include "prefs.h"
  27. #include "util.h"
  28.  
  29. /*-----------------------------------------------------------------------------------*/
  30. /* internal stuff for about.c                                                        */
  31.  
  32. void SetupTheAboutBox(WindowDataHandle theData);
  33. void InitializeTheAboutBox(WindowDataHandle theData);
  34. void OpenTheAboutBox(WindowDataHandle theData);
  35. void ResizeTheAboutBox(WindowDataHandle theData);
  36. void ShutdownTheAboutBox(WindowDataHandle theData);
  37. void DrawTheAboutBox(Boolean isColor);
  38. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  39. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter);
  40.  
  41. Boolean            gUseAlternate;
  42.  
  43. enum
  44. {
  45.     kAboutColorID=134
  46. };
  47.  
  48. short AboutBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  49. {
  50.     short            theDepth;
  51.     
  52.     switch (theMessage)    /* see graphics.h for list of messages*/
  53.     {
  54.         case kKeydown:                            /* close about box on keypress */
  55.         case kMousedown:                        /* or mouseclick */
  56.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  57.             return kSuccess;
  58.             break;
  59.         case kUpdate:
  60.             theDepth=misc&0x7fff;                /* pixel depth */
  61.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  62.             return kSuccess;
  63.             break;
  64.         case kInitialize:
  65.             InitializeTheAboutBox(theData);
  66.             return kFailure;
  67.         case kOpen:
  68.             OpenTheAboutBox(theData);
  69.             return kSuccess;
  70.             break;
  71.         case kStartup:
  72.             SetupTheAboutBox(theData);
  73.             return kSuccess;
  74.             break;
  75.         case kShutdown:
  76.             ShutdownTheAboutBox(theData);
  77.             return kSuccess;
  78.             break;
  79.     }
  80.     
  81.     return kFailure;        /* for all other messages, defer to default processing */
  82. }
  83.  
  84. void SetupTheAboutBox(WindowDataHandle theData)
  85. {
  86.     unsigned char    *theTitle="\pAbout Halma";
  87.     
  88.     (**theData).windowType=noGrowDocProc;    /* plain vanilla window */
  89.     Mymemcpy((Ptr)((**theData).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  90.     (**theData).hasCloseBox=TRUE;
  91.     (**theData).maxDepth=8;
  92.     gUseAlternate=FALSE;
  93. }
  94.  
  95. void InitializeTheAboutBox(WindowDataHandle theData)
  96. {
  97.     (**theData).windowWidth=170;
  98.     (**theData).windowHeight=216;
  99. }
  100.  
  101. void OpenTheAboutBox(WindowDataHandle theData)
  102. {
  103.     KeyMap            rawKeys;
  104.     unsigned short    theKeys[8];
  105.     
  106.     GetKeys(rawKeys);
  107.     Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
  108.     if (theKeys[3]&4)    /* option key down? */
  109.     {
  110.         if (!gUseAlternate)
  111.         {
  112.             gUseAlternate=TRUE;
  113.             (**theData).offscreenNeedsUpdate=TRUE;
  114.         }
  115.     }
  116.     else
  117.     {
  118.         if (gUseAlternate)
  119.         {
  120.             gUseAlternate=FALSE;
  121.             (**theData).offscreenNeedsUpdate=TRUE;
  122.         }
  123.     }
  124. }
  125.  
  126. void ShutdownTheAboutBox(WindowDataHandle theData)
  127. {
  128. }
  129.  
  130. void DrawTheAboutBox(Boolean isColor)
  131. {
  132.     RGBColor        oldForeColor, oldBackColor;
  133.     short            row;
  134.     Handle            textHandle;
  135.     Str255            theLine;
  136.     unsigned long    pos;
  137.     unsigned long    theSize;
  138.     GrafPtr            curPort;
  139.     short            theCenter;
  140.     RGBColor        myGray={49152, 49152, 49152};
  141.     
  142.     GetPort(&curPort);
  143.     if (isColor)
  144.     {
  145.         GetForeColor(&oldForeColor);
  146.         GetBackColor(&oldBackColor);
  147.         RGBForeColor(&myGray);
  148.         PaintRect(&(curPort->portRect));
  149.         RGBForeColor(&oldForeColor);
  150.         RGBBackColor(&oldBackColor);
  151.         TextMode(srcOr);
  152.     }
  153.     else
  154.     {
  155.         FillRect(&(curPort->portRect), black);
  156.         TextMode(srcXor);
  157.     }
  158.     
  159.     theCenter=(curPort->portRect.right-curPort->portRect.left)/2;
  160.     
  161.     TextFont(geneva);
  162.     TextSize(9);
  163.     row=16;
  164.     textHandle=GetResource('TEXT', gUseAlternate ? 129 : 128);
  165.     if (textHandle==0L)
  166.         return;
  167.     if (*textHandle==0L)
  168.         LoadResource(textHandle);
  169.     if (*textHandle==0L)
  170.         return;
  171.     pos=0L;
  172.     theSize=SizeResource(textHandle);
  173.     do
  174.     {
  175.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  176.         DrawTheAboutString(theLine, &row, theCenter);
  177.     }
  178.     while (pos<theSize);
  179.     ReleaseResource(textHandle);
  180.     if (isColor)
  181.         ForeColor(redColor);
  182.     DrawTheAboutString(gMyName, &row, theCenter);
  183.     DrawTheAboutString(gMyOrg, &row, theCenter);
  184.     if (isColor)
  185.         ForeColor(blackColor);
  186.     TextMode(srcCopy);
  187.     TextSize(12);
  188.     TextFont(0);
  189. }
  190.  
  191. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  192. {
  193.     unsigned char    theChar;
  194.     
  195.     theLine[0]=0x00;
  196.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  197.         theLine[++theLine[0]]=theChar;
  198. }
  199.  
  200. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter)
  201. {
  202.     MoveTo(theCenter-StringWidth(theString)/2, *theRow);
  203.     DrawString(theString);
  204.     *theRow+=12;
  205. }
  206.